type User = {
  id: number;
  name: string;
  preferences: {
    language: "en" | "es" | "fr";
    theme: "dark" | "light";
  };
  role: "user" | "admin";
  address: Array<{
    street: string;
    city: string;
    zipCode: string;
  }>;
};

const user: User = {
  id: 0,
  name: "Columbus VonRueden",
  preferences: {
    language: "en",
    theme: "light",
  },
  role: "user",
  address: [
    {
      city: "London",
      street: "Baker Street",
      zipCode: "12345",
    },
  ],
};

// user是一个对象，获取对象的presences中的language
console.log(user["preferences"]["language"]);

// 这样子language就只能是"en" | "es" | "fr"
function setLanguage(language: User["preferences"]["language"]) {
  user.preferences.language = language;
}

/**
 * 
 * @param newAddress 
User 是一个类型，表示用户对象。
User["address"] 表示用户对象中的 address 属性，它的类型是一个数组。
User["address"][number] 表示 address 数组中的元素类型，number 是索引类型，表示数组中的任意索引位置。
 */
function addAddress(newAddress: User["address"][number]) {
  user.address.push(newAddress);
}

export {};
